﻿using AnesSystem.Controls;
using AnesSystem.Models;
using AnesSystem.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AnesSystem.ViewModels.Operation.CQ.CQFY
{
    public class AnesDocSignatureCtrlViewModel : BaseViewModel<AnesDocSignatureCtrlViewModel>
    {
        #region Variables
        //麻醉医生集合 
        private List<AccountModel> _accountAnesModelList = new List<AccountModel>();


        private string _disAnesDoctorName = "";
        private string _disNurseDoctorName = "";
        private string _disCruisingNurseDoctorName = "";
        private string _disoperDoctorName = "";

        private string _zmysAccount = "";
        private string _fmys1Account = "";
        private string _fmys2Account = "";
        private string _fmys3Account = "";



        #endregion


        #region Constructor
        public AnesDocSignatureCtrlViewModel()
        {

        }
        #endregion


        #region Properties

        public string DisAnesDoctorName
        {
            get
            {

                return _disAnesDoctorName;
            }

            set
            {
                _disAnesDoctorName = value;
                RaisePropertyChanged("DisAnesDoctorName");
            }
        }

        public string DisNurseDoctorName
        {
            get
            {
                if (string.IsNullOrEmpty(_disNurseDoctorName)) return "";
                return _disNurseDoctorName;
            }

            set
            {
                _disNurseDoctorName = value;
                RaisePropertyChanged("DisNurseDoctorName");
            }
        }

        public string DisCruisingNurseDoctorName
        {
            get
            {
                return _disCruisingNurseDoctorName;
            }

            set
            {
                _disCruisingNurseDoctorName = value;
                RaisePropertyChanged("DisCruisingNurseDoctorName");
            }
        }



        public string DisoperDoctorName
        {
            get
            {

                if (string.IsNullOrEmpty(_disoperDoctorName)) return "";
                return _disoperDoctorName;
            }

            set
            {
                _disoperDoctorName = value;
                RaisePropertyChanged("DisoperDoctorName");
            }
        }

        public string ZmysAccount
        {
            get
            {
                return _zmysAccount;
            }

            set
            {
                _zmysAccount = value;
                RaisePropertyChanged("ZmysAccount");
            }
        }

        public string Fmys1Account
        {
            get
            {
                return _fmys1Account;
            }

            set
            {
                _fmys1Account = value;
                RaisePropertyChanged("Fmys1Account");
            }
        }

        public string Fmys2Account
        {
            get
            {
                return _fmys2Account;
            }

            set
            {
                _fmys2Account = value;
                RaisePropertyChanged("Fmys2Account");
            }
        }

        public string Fmys3Account
        {
            get
            {
                return _fmys3Account;
            }

            set
            {
                _fmys3Account = value;
                RaisePropertyChanged("Fmys3Account");
            }
        }
        #endregion


        #region 依赖属性


        #endregion


        #region Event


        #endregion


        #region PrivateMethods

        private void ConvertAnesDoctor()
        {
            ZmysAccount = DataManager.Instance.GetAccountNameByID(PatientLink.AnesthesiaRecord.Zmys) +
                (PatientLink.AnesthesiaRecord.ZmysRole == null || "".Equals(PatientLink.AnesthesiaRecord.ZmysRole) ? "" : "(" + PatientLink.AnesthesiaRecord.ZmysRole + ")");
            Fmys1Account = DataManager.Instance.GetAccountNameByID(PatientLink.AnesthesiaRecord.Fmys1) +
                (PatientLink.AnesthesiaRecord.Fmys1Role == null || "".Equals(PatientLink.AnesthesiaRecord.Fmys1Role) ? "" : "(" + PatientLink.AnesthesiaRecord.Fmys1Role + ")");
            Fmys2Account = DataManager.Instance.GetAccountNameByID(PatientLink.AnesthesiaRecord.Fmys2) +
                (PatientLink.AnesthesiaRecord.Fmys2Role == null || "".Equals(PatientLink.AnesthesiaRecord.Fmys2Role) ? "" : "(" + PatientLink.AnesthesiaRecord.Fmys2Role + ")");
            Fmys3Account = DataManager.Instance.GetAccountNameByID(PatientLink.AnesthesiaRecord.Fmys3) +
                (PatientLink.AnesthesiaRecord.Fmys3Role == null || "".Equals(PatientLink.AnesthesiaRecord.Fmys3Role) ? "" : "(" + PatientLink.AnesthesiaRecord.Fmys3Role + ")");
        }
        //初始化时手术医生
        private void ConvertOperDoctor1()
        {
            _disoperDoctorName = "";
            if (PatientLink.AnesthesiaRecord.OperDoctor1 != null && PatientLink.AnesthesiaRecord.OperDoctor1.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.OperDoctor1));
                if (a != null) _disoperDoctorName += a.TrueName + ", ";
            }
            if (PatientLink.AnesthesiaRecord.OperDoctor1Assistant1 != null && PatientLink.AnesthesiaRecord.OperDoctor1Assistant1.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.OperDoctor1Assistant1));
                if (a != null) _disoperDoctorName += a.TrueName + ", ";
            }
            if (PatientLink.AnesthesiaRecord.OperDoctor1Assistant2 != null && PatientLink.AnesthesiaRecord.OperDoctor1Assistant2.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.OperDoctor1Assistant2));
                if (a != null) _disoperDoctorName += a.TrueName + ", ";
            }
            if (PatientLink.AnesthesiaRecord.OperDoctor1Assistant3 != null && PatientLink.AnesthesiaRecord.OperDoctor1Assistant3.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.OperDoctor1Assistant3));
                if (a != null) _disoperDoctorName += a.TrueName + ", ";
            }
            if (!string.IsNullOrEmpty(_disoperDoctorName)) DisoperDoctorName = _disoperDoctorName.Substring(0, _disoperDoctorName.Length - 2);
        }



        //初始化洗手护士
        private void ConvertNurseDoctor()
        {
            _disNurseDoctorName = "";
            if (PatientLink.AnesthesiaRecord.Xshs1 != null && PatientLink.AnesthesiaRecord.Xshs1.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.Xshs1));
                if (a != null) _disNurseDoctorName += a.TrueName + ", ";
            }
            if (PatientLink.AnesthesiaRecord.Xshs2 != null && PatientLink.AnesthesiaRecord.Xshs2.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.Xshs2));
                if (a != null) _disNurseDoctorName += a.TrueName + ", ";
            }
            if (PatientLink.AnesthesiaRecord.Xshs2 != null && PatientLink.AnesthesiaRecord.Xshs2.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.Xshs3));
                if (a != null) _disNurseDoctorName += a.TrueName + ", ";
            }
            if (!string.IsNullOrEmpty(_disNurseDoctorName)) DisNurseDoctorName = _disNurseDoctorName.Substring(0, _disNurseDoctorName.Length - 2);
        }

        //初始化巡航护士
        private void ConvertCruiseNurseDoctor()
        {
            _disCruisingNurseDoctorName = "";
            if (PatientLink.AnesthesiaRecord.Xhhs1 != null && PatientLink.AnesthesiaRecord.Xhhs1.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.Xhhs1));
                if (a != null) _disCruisingNurseDoctorName += a.TrueName + ", ";
            }
            if (PatientLink.AnesthesiaRecord.Xhhs2 != null && PatientLink.AnesthesiaRecord.Xhhs2.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.Xhhs2));
                if (a != null) _disCruisingNurseDoctorName += a.TrueName + ", ";
            }
            if (PatientLink.AnesthesiaRecord.Xhhs3 != null && PatientLink.AnesthesiaRecord.Xhhs3.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.Xhhs3));
                if (a != null) _disCruisingNurseDoctorName += a.TrueName + ", ";
            }
            if (!string.IsNullOrEmpty(_disCruisingNurseDoctorName)) DisCruisingNurseDoctorName = _disCruisingNurseDoctorName.Substring(0, _disCruisingNurseDoctorName.Length - 2);
        }



        #endregion


        #region Public/ProtectedMethods
        public void Load_page()
        {
            ConvertAnesDoctor();
            ConvertOperDoctor1();
            ConvertNurseDoctor();
            ConvertCruiseNurseDoctor();
        }

        //手术医生控件

        public void OperationTanChu()
        {
            OperationOptCtrl no = new OperationOptCtrl();
            DrugAndEventWindow.Instance.CusContent = no;
            DrugAndEventWindow.Instance.Width = 450;
            DrugAndEventWindow.Instance.Height = 350;
            DrugAndEventWindow.Instance.ShowDialog();
            no.KeepAccountModel += (newAccountModelList) =>
            {
                DisoperDoctorName = newAccountModelList;
            };
        }

        //洗手护士控件
        public void NurseTanChu()
        {
            WashNurseCtrl no = new WashNurseCtrl();
            DrugAndEventWindow.Instance.CusContent = no;
            DrugAndEventWindow.Instance.Width = 350;
            DrugAndEventWindow.Instance.Height = 250;
            DrugAndEventWindow.Instance.ShowDialog();
            no.KeepAccountModel += (newAccountModelList) =>
            {
                DisNurseDoctorName = newAccountModelList;
            };
        }



        //巡航护士控件
        public void CruisingNurseTanChu()
        {
            CruiseNurseCtrl no = new CruiseNurseCtrl();
            DrugAndEventWindow.Instance.Width = 350;
            DrugAndEventWindow.Instance.Height = 250;
            DrugAndEventWindow.Instance.CusContent = no;
            DrugAndEventWindow.Instance.ShowDialog();
            no.KeepAccountModel += (newAccountModelList) =>
            {
                DisCruisingNurseDoctorName = newAccountModelList;
            };
        }


        //麻醉医生控件
        public void AnesDoctorTanChu()
        {

            AnesDoctorOpt ado = new AnesDoctorOpt();
            DrugAndEventWindow.Instance.CusContent = ado;
            DrugAndEventWindow.Instance.Width = 450;
            DrugAndEventWindow.Instance.Height = 350;
            DrugAndEventWindow.Instance.ShowDialog();
            DoctorOptViewModel vm = ado.DataContext as DoctorOptViewModel;
            ado.KeepAccountModel += (newAccountModelList) =>
            {
                ZmysAccount = DataManager.Instance.GetAccountNameByID(vm.ZmysAccount) + (vm.ZmysRole == null || "".Equals(vm.ZmysRole) ? "" : "(" + vm.ZmysRole + ")");
                Fmys1Account = DataManager.Instance.GetAccountNameByID(vm.Fmys1Account) + (vm.Fmys1Role == null || "".Equals(vm.Fmys1Role) ? "" : "(" + vm.Fmys1Role + ")");
                Fmys2Account = DataManager.Instance.GetAccountNameByID(vm.Fmys2Account) + (vm.Fmys2Role == null || "".Equals(vm.Fmys2Role) ? "" : "(" + vm.Fmys2Role + ")");
                Fmys3Account = DataManager.Instance.GetAccountNameByID(vm.Fmys3Account) + (vm.Fmys3Role == null || "".Equals(vm.Fmys3Role) ? "" : "(" + vm.Fmys3Role + ")");
            };
        }
        #endregion


        #region EventHandlers

        #endregion
    }
}

